<template>
    <div>
        <el-row class="normal">
            <el-col :span="4">
                <el-tabs
                    v-model="activeName"
                    type="card"
                    @tab-click="handleClick"
                >
                    <el-tab-pane
                        label="门诊病历"
                        name="medicalRecords"
                        class="limit-height"
                    >
                        <span slot="label">
                            门诊病历
                            <el-badge
                                v-if="
                                    electronicMedicalData.outpatient.length > 0
                                "
                                :value="electronicMedicalData.outpatient.length"
                                class="tab-content-badge"
                            ></el-badge>
                        </span>
                        <div
                            v-for="item in electronicMedicalData.outpatient"
                            :key="item.id"
                            :class="[
                                item.id === activeId ? activeClass : '',
                                normalClass,
                            ]"
                            @click="getInfo(item.id)"
                        >
                            门诊病历:{{ item.outPatientTreatmentDate }}
                        </div>
                    </el-tab-pane>
                    <el-tab-pane label="入院记录" name="admissionRecord">
                        <span slot="label">
                            入院记录
                            <el-badge
                                v-if="electronicMedicalData.hospital.length > 0"
                                :value="electronicMedicalData.hospital.length"
                                class="tab-content-badge"
                            ></el-badge>
                        </span>
                        <div
                            v-for="item in electronicMedicalData.hospital"
                            :key="item.id"
                            :class="[
                                item.id === activeId ? activeClass : '',
                                normalClass,
                            ]"
                            @click="getInfo(item.id)"
                        >
                            入院记录:{{ item.admissionDate }}
                        </div>
                    </el-tab-pane>
                </el-tabs>
            </el-col>
            <el-col :span="20">
                <div
                    class="a4"
                    style="position: relative"
                    v-if="activeName === 'medicalRecords'"
                >
                    <el-row class="title">门诊病历</el-row>
                    <div style="position: absolute; top: 10px">
                        <el-button size="mini" @click="dataOutput"
                            >标注导出
                        </el-button>
                        <el-button size="mini" @click="operateMarkLabel"
                            >{{ isClosed ? '结束标注' : '开始标注' }}
                        </el-button>
                        <el-button size="mini" @click="operateShowLabel"
                            >{{ isShowTag ? '隐藏标签' : '显示标签' }}
                        </el-button>
                        <el-button size="mini" @click="reGet"
                            >重新获取
                        </el-button>
                    </div>
                    <el-row>
                        <el-col class="heiti" :span="4"
                            >姓名:{{ infoData.name }}
                        </el-col>
                        <el-col class="heiti" :span="6"
                            >性别:{{ infoData.sex }}
                        </el-col>
                        <el-col class="heiti" :span="6"
                            >年龄:{{ infoData.age }}
                        </el-col>
                        <el-col class="heiti" :span="8"
                            >就诊日期:{{ infoData.outPatientTreatmentDate }}
                        </el-col>
                        <el-col class="heiti" :span="4"
                            >门诊卡号:{{ infoData.outPatientCardNumber }}
                        </el-col>
                        <el-col class="heiti" :span="6"
                            >科室:{{ infoData.outPatientDepartment }}
                        </el-col>
                        <el-col class="heiti" :span="6"
                            >患者ID:{{ infoData.patientId }}
                        </el-col>
                        <el-col class="heiti" :span="8"
                            >就诊ID:{{ infoData.outPatientTreatmentId }}
                        </el-col>
                    </el-row>
                    <div class="cut-line"></div>
                    <el-row>
                        <el-col class="heiti" :span="6">主诉： </el-col>
                        <el-col :span="24">
                            <mark-label
                                name="主诉"
                                :isShowTag="isShowTag"
                                :labels="diagnosticBasisArray"
                                :key="timer"
                                :data-content="zhusu"
                                :delete-label-father-method="deleteLabel"
                                :add-label-father-method="addLabel"
                                :isClosed="isClosed"
                            />
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col class="heiti" :span="6">现病史： </el-col>
                        <el-col :span="24">
                            <mark-label
                                name="现病史"
                                :isShowTag="isShowTag"
                                :labels="diagnosticBasisArray"
                                :key="timer"
                                :data-content="xianbing"
                                :delete-label-father-method="deleteLabel"
                                :add-label-father-method="addLabel"
                                :isClosed="isClosed"
                            />
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col class="heiti" :span="6">既往史： </el-col>
                        <el-col :span="24">
                            <mark-label
                                name="既往史"
                                :isShowTag="isShowTag"
                                :labels="diagnosticBasisArray"
                                :key="timer"
                                :data-content="jiwangshi"
                                :delete-label-father-method="deleteLabel"
                                :add-label-father-method="addLabel"
                                :isClosed="isClosed"
                            />
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col class="heiti" :span="6">过敏史： </el-col>
                        <el-col :span="24">
                            <mark-label
                                name="过敏史"
                                :isShowTag="isShowTag"
                                :labels="diagnosticBasisArray"
                                :key="timer"
                                :data-content="guomin"
                                :delete-label-father-method="deleteLabel"
                                :add-label-father-method="addLabel"
                                :isClosed="isClosed"
                            />
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col class="heiti" :span="6">体格检查： </el-col>
                        <el-col :span="24">
                            <mark-label
                                name="体格检查"
                                :isShowTag="isShowTag"
                                :labels="diagnosticBasisArray"
                                :key="timer"
                                :data-content="tigejiancha"
                                :delete-label-father-method="deleteLabel"
                                :add-label-father-method="addLabel"
                                :isClosed="isClosed"
                            />
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col class="heiti" :span="6">辅助检查： </el-col>
                        <el-col :span="24">
                            <mark-label
                                name="辅助检查"
                                :isShowTag="isShowTag"
                                :labels="diagnosticBasisArray"
                                :key="timer"
                                :data-content="fuzhujiancha"
                                :delete-label-father-method="deleteLabel"
                                :add-label-father-method="addLabel"
                                :isClosed="isClosed"
                            />
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col class="heiti" :span="6">初步诊断： </el-col>
                        <el-col :span="24">
                            <mark-label
                                :key="timer"
                                :isShowTag="isShowTag"
                                :labels="diagnosticBasisArray"
                                name="初步诊断"
                                :data-content="chubuzhenduan"
                                :delete-label-father-method="deleteLabel"
                                :add-label-father-method="addLabel"
                                :isClosed="isClosed"
                            />
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col class="heiti" :span="6">处理意见： </el-col>
                        <el-col :span="24">
                            <mark-label
                                name="处理意见"
                                :isShowTag="isShowTag"
                                :labels="diagnosticBasisArray"
                                :key="timer"
                                :data-content="chuliyijian"
                                :delete-label-father-method="deleteLabel"
                                :add-label-father-method="addLabel"
                                :isClosed="isClosed"
                            />
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col class="heiti" :span="6">备注： </el-col>
                        <el-col :span="24">
                            <mark-label
                                name="备注"
                                :isShowTag="isShowTag"
                                :labels="diagnosticBasisArray"
                                :key="timer"
                                :data-content="beizhu"
                                :delete-label-father-method="deleteLabel"
                                :add-label-father-method="addLabel"
                                :isClosed="isClosed"
                            />
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="6" :offset="18"
                            >医生：{{ infoData.doctorName }}
                        </el-col>
                    </el-row>
                </div>
                <div class="a4" style="position: relative" v-else>
                    <el-row class="title">入院记录</el-row>
                    <div style="position: absolute; top: 10px">
                        <el-button size="mini" @click="dataOutput"
                            >标注导出
                        </el-button>
                        <el-button size="mini" @click="operateMarkLabel"
                            >{{ isClosed ? '结束标注' : '开始标注' }}
                        </el-button>
                        <el-button size="mini" @click="operateShowLabel"
                            >{{ isShowTag ? '隐藏标签' : '显示标签' }}
                        </el-button>
                        <el-button size="mini" @click="reGet"
                            >重新获取
                        </el-button>
                    </div>
                    <el-row>
                        <el-col class="heiti" :span="5"
                            >姓名:{{ infoData.name }}
                        </el-col>
                        <el-col class="heiti" :span="5"
                            >性别:{{ infoData.sex }}
                        </el-col>
                        <el-col class="heiti" :span="5"
                            >年龄:{{ infoData.age }}
                        </el-col>
                        <el-col class="heiti" :span="9"
                            >入院日期:{{ infoData.admissionDate }}
                        </el-col>
                        <el-col class="heiti" :span="5"
                            >住院号:{{ infoData.admissionInpatientNumber }}
                        </el-col>
                        <el-col class="heiti" :span="5"
                            >病区:{{ infoData.admissionWard }}
                        </el-col>
                        <el-col class="heiti" :span="5"
                            >床号:{{ infoData.admissionBedNumber }}
                        </el-col>
                        <el-col class="heiti" :span="9"
                            >患者HIS码:{{ infoData.registrationId }}
                        </el-col>
                    </el-row>
                    <div class="cut-line"></div>
                    <el-row>
                        <el-col class="heiti" :span="6">主诉： </el-col>
                        <el-col :span="24">
                            <mark-label
                                :key="timer"
                                :isShowTag="isShowTag"
                                :labels="diagnosticBasisArray"
                                name="主诉"
                                :data-content="zhusu"
                                :delete-label-father-method="deleteLabel"
                                :add-label-father-method="addLabel"
                                :isClosed="isClosed"
                            />
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col class="heiti" :span="6">现病史： </el-col>
                        <el-col :span="24">
                            <mark-label
                                name="现病史"
                                :isShowTag="isShowTag"
                                :labels="diagnosticBasisArray"
                                :key="timer"
                                :data-content="xianbing"
                                :delete-label-father-method="deleteLabel"
                                :add-label-father-method="addLabel"
                                :isClosed="isClosed"
                            />
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col class="heiti" :span="6">既往史： </el-col>
                        <el-col :span="24">
                            <mark-label
                                name="既往史"
                                :isShowTag="isShowTag"
                                :labels="diagnosticBasisArray"
                                :key="timer"
                                :data-content="jiwangshi"
                                :delete-label-father-method="deleteLabel"
                                :add-label-father-method="addLabel"
                                :isClosed="isClosed"
                            />
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col class="heiti" :span="6">手术史： </el-col>
                        <el-col :span="24">
                            <mark-label
                                name="手术史"
                                :isShowTag="isShowTag"
                                :labels="diagnosticBasisArray"
                                :key="timer"
                                :data-content="shoushushi"
                                :delete-label-father-method="deleteLabel"
                                :add-label-father-method="addLabel"
                                :isClosed="isClosed"
                            />
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col class="heiti" :span="6">个人史： </el-col>
                        <el-col :span="24">
                            <mark-label
                                name="个人史"
                                :isShowTag="isShowTag"
                                :labels="diagnosticBasisArray"
                                :key="timer"
                                :data-content="gerenshi"
                                :delete-label-father-method="deleteLabel"
                                :add-label-father-method="addLabel"
                                :isClosed="isClosed"
                            />
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col class="heiti" :span="6">月经史： </el-col>
                        <el-col :span="24">
                            <mark-label
                                name="月经史"
                                :isShowTag="isShowTag"
                                :labels="diagnosticBasisArray"
                                :key="timer"
                                :data-content="yuejingshi"
                                :delete-label-father-method="deleteLabel"
                                :add-label-father-method="addLabel"
                                :isClosed="isClosed"
                            />
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col class="heiti" :span="6">家族史： </el-col>
                        <el-col :span="24">
                            <mark-label
                                name="家族史"
                                :isShowTag="isShowTag"
                                :labels="diagnosticBasisArray"
                                :key="timer"
                                :data-content="jiazushi"
                                :delete-label-father-method="deleteLabel"
                                :add-label-father-method="addLabel"
                                :isClosed="isClosed"
                            />
                        </el-col>
                    </el-row>
                    <!-- <el-row>
                        <el-col
                            :span="24"
                            class="heiti"
                        >传染病史：
                        </el-col>
                        <el-col :span="24">
                            <mark-label
                                :key="timer"
                                name="传染病史"
                                :isShowTag="isShowTag"
                                :labels="diagnosticBasisArray"
                                :data-content='chuanranbing'
                                :delete-label-father-method='deleteLabel'
                                :add-label-father-method='addLabel'
                                :isClosed="isClosed"
                            />
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col
                            :span="24"
                            class="heiti"
                        >预防接种史：
                        </el-col>
                        <el-col :span="24">
                            <mark-label
                                :key="timer"
                                name="预防接种史"
                                :isShowTag="isShowTag"
                                :labels="diagnosticBasisArray"
                                :data-content='yufangjiezhong'
                                :delete-label-father-method='deleteLabel'
                                :add-label-father-method='addLabel'
                                :isClosed="isClosed"
                            />
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col
                            :span="24"
                            class="heiti"
                        >输血史：
                        </el-col>
                        <el-col :span="24">
                            <mark-label
                                :key="timer"
                                name="输血史"
                                :isShowTag="isShowTag"
                                :labels="diagnosticBasisArray"
                                :data-content='shuxue'
                                :delete-label-father-method='deleteLabel'
                                :add-label-father-method='addLabel'
                                :isClosed="isClosed"
                            />
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col
                            class="heiti"
                            :span="6"
                        >过敏史：
                        </el-col>
                        <el-col :span="24">
                            <mark-label
                                name="过敏史"
                                :isShowTag="isShowTag"
                                :labels="diagnosticBasisArray"
                                :key="timer"
                                :data-content='guomin'
                                :delete-label-father-method='deleteLabel'
                                :add-label-father-method='addLabel'
                                :isClosed="isClosed"
                            />
                        </el-col>
                    </el-row> -->
                    <el-row>
                        <el-col :span="24" class="second-title heiti"
                            >体格检查
                        </el-col>
                        <el-col :span="4"
                            >体温(T):{{
                                infoData.physicalCheckTemperature
                            }}</el-col
                        >
                        <el-col :span="4"
                            >脉搏:{{ infoData.physicalCheckPulse }}</el-col
                        >
                        <el-col :span="4"
                            >呼吸 :{{
                                infoData.physicalCheckRespiratoryRate
                            }}</el-col
                        >
                        <el-col :span="4"
                            >血压:{{ infoData.physicalSBPAndDBP }}</el-col
                        >
                        <el-col :span="4"
                            >身高:{{ infoData.physicalHeight }}</el-col
                        >
                        <el-col :span="4"
                            >体重:{{ infoData.physicalWeight }}</el-col
                        >
                        <el-col :span="24">
                            <mark-label
                                name="体格检查"
                                :isShowTag="isShowTag"
                                :labels="diagnosticBasisArray"
                                :key="timer"
                                :data-content="tigejiancha"
                                :delete-label-father-method="deleteLabel"
                                :add-label-father-method="addLabel"
                                :isClosed="isClosed"
                            />
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="24" class="second-title heiti"
                            >辅助检查
                        </el-col>
                        <el-col :span="24">
                            <mark-label
                                name="辅助检查"
                                :isShowTag="isShowTag"
                                :key="timer"
                                :labels="diagnosticBasisArray"
                                :data-content="fuzhujiancha"
                                :delete-label-father-method="deleteLabel"
                                :add-label-father-method="addLabel"
                                :isClosed="isClosed"
                            />
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="24" class="second-title heiti"
                            >初步诊断
                        </el-col>
                        <el-col :span="24">
                            <mark-label
                                :key="timer"
                                name="初步诊断"
                                :isShowTag="isShowTag"
                                :labels="diagnosticBasisArray"
                                :data-content="chubuzhenduan"
                                :delete-label-father-method="deleteLabel"
                                :add-label-father-method="addLabel"
                                :isClosed="isClosed"
                            />
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col class="heiti" :span="12"
                            >住院医生:{{ infoData.inHospitalDoctorName }}
                        </el-col>
                        <el-col class="heiti" :span="12"
                            >记录时间:{{ infoData.admissionDate }}
                        </el-col>
                        <el-col class="heiti" :span="12"
                            >主治医生:{{ infoData.treatDoctorName }}
                        </el-col>
                        <el-col class="heiti" :span="12"
                            >记录时间:{{ infoData.admissionDate }}
                        </el-col>
                    </el-row>
                </div>
            </el-col>
        </el-row>
    </div>
</template>
<script>
import MarkLabel from '@templates/components/MarkLabel.vue';
import _ from 'lodash';
import { DateUtil } from '@/client/libs/date';

export default {
    name: 'DiagnosisDetailElectronicMedical',
    props: {
        electronicMedicalData: { type: Object },
        activeName: {
            type: String,
            default: 'admissionRecord',
        },
    },
    components: {
        MarkLabel,
    },
    data() {
        return {
            currentId: '', //当前ID
            diagnosticBasisArray: [], //诊断依据字典
            submitFormLabels: {}, // 提交的json
            submitFormTexts: [], // 提交的text
            timer: '',
            isClosed: false,
            isShowTag: false,
            infoData: {},
            srcList: [],
            checkList: {},
            activeId: '',
            activeClass: 'is-active',
            normalClass: 'btn-item',
            textLabelIndex: {},
            zhusu: {
                title: '主诉',
                text: '',
                labels: [],
            },
            gerenshi: {
                title: '个人史',
                text: '',
                labels: [],
            },
            xianbing: {
                title: '现病史',
                text: '',
                labels: [],
            },
            jiwangshi: {
                title: '既往史',
                text: '',
                labels: [],
            },
            shoushushi: {
                title: '手术史',
                text: '',
                labels: [],
            },
            yuejingshi: {
                title: '月经史',
                text: '',
                labels: [],
            },
            jiazushi: {
                title: '家族史',
                text: '',
                labels: [],
            },
            tigejiancha: {
                title: '体格检查',
                text: '',
                labels: [],
            },
            chubuzhenduan: {
                title: '初步诊断',
                text: '',
                labels: [],
            },
            chuliyijian: {
                title: '处理意见',
                text: '',
                labels: [],
            },
            beizhu: {
                title: '备注',
                text: '',
                labels: [],
            },
            fuzhujiancha: {
                title: '辅助检查',
                text: '',
                labels: [],
            },

            chuanranbing: {
                title: '传染病史',
                text: '',
                labels: [],
            },
            yufangjiezhong: {
                title: '预防接种史',
                text: '',
                labels: [],
            },
            shuxue: {
                title: '输血史',
                text: '',
                labels: [],
            },
            guomin: {
                title: '过敏史',
                text: '',
                labels: [],
            },
        };
    },
    computed: {},
    mounted() {
        this.getDiagnosticBasis();
    },
    watch: {
        electronicMedicalData: {
            handler(newName, oldName) {
                if (
                    newName.hospital.length !== 0 &&
                    newName.outpatient.length === 0
                ) {
                    this.getInfo(newName.hospital[0].id);
                } else {
                    this.getInfo(newName.outpatient[0].id);
                }
            },
            immediate: false,
            deep: true,
        },
    },
    methods: {
        operateMarkLabel() {
            if (!this.isClosed) {
                this.isShowTag = true;
            }
            this.isClosed = !this.isClosed;
        },
        operateShowLabel() {
            if (this.isClosed) {
                this.isClosed = false;
            }
            this.isShowTag = !this.isShowTag;
        },
        reGet() {
            this.$confirm('此操作将重新获取数据, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
            })
                .then(() => {
                    const pathologyId = sessionStorage.getItem('pathologyId');
                    this.$axios({
                        method: 'GET',
                        url: `/PROXY-Remote/outpatientWithHospital/againCreateAsyncTask/forOutpatientWithHospitalOfCancerHospital/by/${pathologyId}`,
                    })
                        .then((res) => {
                            if (res.data.code === 200) {
                                this.$message.info(
                                    '正在获取数据中，请稍后......'
                                );
                            }
                        })
                        .catch((error) => {
                            this.$message.error(error.message);
                        });
                })
                .catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消',
                    });
                });
        },
        dataOutput() {
            let textContent = {};
            Object.keys(this.submitFormLabels).map((key) => {
                const content = this.submitFormTexts.find((item) => {
                    return item.title === key;
                });
                textContent[content.title] = content.text || '';
            });
            let urlObject = window.URL || window.webkitURL || window;
            let export_blob = new Blob([
                JSON.stringify({
                    texts: textContent,
                    labels: this.submitFormLabels,
                }),
            ]);
            let save_link = document.createElementNS(
                'http://www.w3.org/1999/xhtml',
                'a'
            );
            save_link.href = urlObject.createObjectURL(export_blob);
            save_link.download = `电子病例标注数据${DateUtil.now()}.json`;
            let ev = document.createEvent('MouseEvents');
            ev.initMouseEvent(
                'click',
                true,
                false,
                window,
                0,
                0,
                0,
                0,
                0,
                false,
                false,
                false,
                false,
                0,
                null
            );
            save_link.dispatchEvent(ev);
        },
        deleteLabel(name, text, labels, label) {
            console.log('delete', name, text, labels, label);
            this.updateLabels({
                id: this.currentId,
                textLabelIndex: JSON.stringify(this.submitFormLabels),
            });
        },
        addLabel(name, text, labels, label) {
            console.log('add', name, text, labels, label);
            let textContent = [];
            Object.keys(this.submitFormLabels).map((key) => {
                const content = this.submitFormTexts.find((item) => {
                    return item.title === key;
                });
                textContent.push({ [content.title]: content.text });
            });
            this.updateLabels({
                id: this.currentId,
                textLabelIndex: JSON.stringify(this.submitFormLabels),
            });
        },
        updateLabels(data) {
            if (!!data.id) {
                this.$axios({
                    method: 'POST',
                    url: `/PROXY-Remote/diagnosticBasis/updateDiagnosticBasis/by/id`,
                    data: data,
                })
                    .then((res) => {
                        if (res.data.code !== 200) {
                            this.$message.error({
                                message: '标注接口请求错误',
                            });
                        }
                    })
                    .catch((error) => {
                        this.$message.error(error.message);
                    });
            }
        },
        handleClick(tab, event) {
            this.currentId = '';
            this.submitFormLabels = {};
            this.zhusu.labels = [];
            this.gerenshi.labels = [];
            this.xianbing.labels = [];
            this.jiwangshi.labels = [];
            this.shoushushi.labels = [];
            this.yuejingshi.labels = [];
            this.jiazushi.labels = [];
            this.chuanranbing.labels = [];
            this.yufangjiezhong.labels = [];
            this.shuxue.labels = [];
            this.guomin.labels = [];

            this.tigejiancha.labels = [];
            this.chubuzhenduan.labels = [];
            this.chuliyijian.labels = [];
            this.beizhu.labels = [];
            this.fuzhujiancha.labels = [];
            this.zhusu.text = '';
            this.gerenshi.text = '';
            this.xianbing.text = '';
            this.jiwangshi.text = '';
            this.shoushushi.text = '';
            this.yuejingshi.text = '';
            this.jiazushi.text = '';
            this.chuanranbing.text = '';
            this.yufangjiezhong.text = '';
            this.shuxue.text = '';
            this.guomin.text = '';
            this.tigejiancha.text = '';
            this.chubuzhenduan.text = '';
            this.chuliyijian.text = '';
            this.beizhu.text = '';
            if (tab.name === 'medicalRecords') {
                if (this.electronicMedicalData.outpatient.length > 0) {
                    this.getInfo(this.electronicMedicalData.outpatient[0].id);
                }
            } else if (tab.name === 'admissionRecord') {
                if (this.electronicMedicalData.hospital.length > 0) {
                    this.getInfo(this.electronicMedicalData.hospital[0].id);
                }
            } else {
            }
        },
        getInfo(pId) {
            this.timer = new Date().getTime();
            this.$axios({
                method: 'GET',
                url: `/PROXY-Remote/outpatientWithHospital/get/by/${pId}`,
            }).then((res) => {
                if (res && res.data.code === 200) {
                    this.infoData = res.data.data;
                    this.activeId = pId;
                    this.srcList = [];
                    this.zhusu.text = this.infoData.chiefComplaint;
                    this.gerenshi.text = this.infoData.personalHistory || '';
                    this.xianbing.text = this.infoData.hpi || '';
                    this.jiwangshi.text = this.infoData.previousHistory || '';
                    this.shoushushi.text = this.infoData.operationHistory || '';
                    this.yuejingshi.text = this.infoData.menstrualHistory || '';
                    this.jiazushi.text = this.infoData.familyHistory || '';

                    this.chuanranbing.text =
                        this.infoData.historyOfInfection || '';
                    this.yufangjiezhong.text =
                        this.infoData.historyOfPreventiveInoculation || '';
                    this.shuxue.text = this.infoData.transfusionHistory || '';
                    this.guomin.text = this.infoData.allergyHistory || '';

                    this.tigejiancha.text = this.infoData.physicalCheck || '';
                    this.chubuzhenduan.text =
                        this.infoData.primaryDiagnosis || '';
                    this.chuliyijian.text = this.infoData.doctorAdvise || '';
                    this.beizhu.text = this.infoData.remark || '';
                    this.fuzhujiancha.text =
                        this.infoData.accessoryExamination || '';
                    this.submitFormTexts = [
                        this.zhusu,
                        this.gerenshi,
                        this.xianbing,
                        this.jiwangshi,
                        this.shoushushi,
                        this.yuejingshi,
                        this.jiazushi,
                        this.tigejiancha,
                        this.chubuzhenduan,
                        this.chuliyijian,
                        this.beizhu,
                        this.fuzhujiancha,
                        this.chuanranbing,
                        this.yufangjiezhong,
                        this.shuxue,
                        this.guomin,
                    ];
                    this.submitFormTexts.forEach((item) => {
                        this.submitFormLabels[item.title] = [];
                    });
                    if (res.data.data.analysisStatus === 2) {
                        this.$message.warning('电子病历nlp分析异常');
                    } else {
                        this.getNLPDiagnosis(pId);
                    }
                }
            });
        },
        getNLPDiagnosis(pId) {
            this.zhusu.labels = [];
            this.gerenshi.labels = [];
            this.xianbing.labels = [];
            this.jiwangshi.labels = [];
            this.shoushushi.labels = [];
            this.yuejingshi.labels = [];
            this.jiazushi.labels = [];
            this.tigejiancha.labels = [];
            this.chubuzhenduan.labels = [];
            this.chuliyijian.labels = [];
            this.beizhu.labels = [];
            this.fuzhujiancha.labels = [];
            this.chuanranbing.labels = [];
            this.yufangjiezhong.labels = [];
            this.shuxue.labels = [];
            this.guomin.labels = [];
            const _this = this;

            this.$axios({
                method: 'GET',
                //url: `/PROXY-Remote/diagnosticBasis/get/by/0761531b293d973edbaf8eb7e6941793/${pathologyId}`,
                url: `/PROXY-Remote/diagnosticBasis/test/get/by/${pId}`,
            }).then((res) => {
                if (res && res.data.code === 200) {
                    this.currentId = res.data.data.id;
                    let markData = JSON.parse(res.data.data.textLabelIndex);
                    _this.textLabelIndex = {};
                    Object.keys(markData).map((key) => {
                        if (key === '主诉') {
                            markData[key].forEach((item) => {
                                _this.zhusu.labels.push({
                                    entity: item.entity,
                                    label: item.label,
                                    start: item.start,
                                    end: item.end,
                                    color:
                                        item.label.search('阴性') !== -1
                                            ? 'success'
                                            : item.label.search('阳性') !== -1
                                            ? 'danger'
                                            : '',
                                });
                            });
                            this.submitFormLabels['主诉'] =
                                _this.zhusu.labels || [];
                        } else if (key === '个人史') {
                            markData[key].forEach((item) => {
                                _this.gerenshi.labels.push({
                                    entity: item.entity,
                                    label: item.label,
                                    start: item.start,
                                    end: item.end,
                                    color:
                                        item.label.search('阴性') !== -1
                                            ? 'success'
                                            : item.label.search('阳性') !== -1
                                            ? 'danger'
                                            : '',
                                });
                            });
                            this.submitFormLabels['个人史'] =
                                _this.gerenshi.labels || [];
                        } else if (key === '现病史') {
                            markData[key].forEach((item) => {
                                _this.xianbing.labels.push({
                                    entity: item.entity,
                                    label: item.label,
                                    start: item.start,
                                    end: item.end,
                                    color:
                                        item.label.search('阴性') !== -1
                                            ? 'success'
                                            : item.label.search('阳性') !== -1
                                            ? 'danger'
                                            : '',
                                });
                            });
                            this.submitFormLabels['现病史'] =
                                _this.xianbing.labels || [];
                        } else if (key === '既往史') {
                            markData[key].forEach((item) => {
                                _this.jiwangshi.labels.push({
                                    entity: item.entity,
                                    label: item.label,
                                    start: item.start,
                                    end: item.end,
                                    color:
                                        item.label.search('阴性') !== -1
                                            ? 'success'
                                            : item.label.search('阳性') !== -1
                                            ? 'danger'
                                            : '',
                                });
                            });
                            this.submitFormLabels['既往史'] =
                                _this.jiwangshi.labels || [];
                        } else if (key === '手术史') {
                            markData[key].forEach((item) => {
                                _this.shoushushi.labels.push({
                                    entity: item.entity,
                                    label: item.label,
                                    start: item.start,
                                    end: item.end,
                                    color:
                                        item.label.search('阴性') !== -1
                                            ? 'success'
                                            : item.label.search('阳性') !== -1
                                            ? 'danger'
                                            : '',
                                });
                            });
                            this.submitFormLabels['手术史'] =
                                _this.shoushushi.labels || [];
                        } else if (key === '月经史') {
                            markData[key].forEach((item) => {
                                _this.yuejingshi.labels.push({
                                    entity: item.entity,
                                    label: item.label,
                                    start: item.start,
                                    end: item.end,
                                    color:
                                        item.label.search('阴性') !== -1
                                            ? 'success'
                                            : item.label.search('阳性') !== -1
                                            ? 'danger'
                                            : '',
                                });
                            });
                            this.submitFormLabels['月经史'] =
                                _this.yuejingshi.labels || [];
                        } else if (key === '家族史') {
                            markData[key].forEach((item) => {
                                _this.jiazushi.labels.push({
                                    entity: item.entity,
                                    label: item.label,
                                    start: item.start,
                                    end: item.end,
                                    color:
                                        item.label.search('阴性') !== -1
                                            ? 'success'
                                            : item.label.search('阳性') !== -1
                                            ? 'danger'
                                            : '',
                                });
                            });
                            this.submitFormLabels['家族史'] =
                                _this.jiazushi.labels || [];
                        } else if (key === '体格检查') {
                            markData[key].forEach((item) => {
                                _this.tigejiancha.labels.push({
                                    entity: item.entity,
                                    label: item.label,
                                    start: item.start,
                                    end: item.end,
                                    color:
                                        item.label.search('阴性') !== -1
                                            ? 'success'
                                            : item.label.search('阳性') !== -1
                                            ? 'danger'
                                            : '',
                                });
                            });
                            this.submitFormLabels['体格检查'] =
                                _this.tigejiancha.labels || [];
                        } else if (key === '传染病史') {
                            markData[key].forEach((item) => {
                                _this.chuanranbing.labels.push({
                                    entity: item.entity,
                                    label: item.label,
                                    start: item.start,
                                    end: item.end,
                                    color:
                                        item.label.search('阴性') !== -1
                                            ? 'success'
                                            : item.label.search('阳性') !== -1
                                            ? 'danger'
                                            : '',
                                });
                            });
                            this.submitFormLabels['传染病史'] =
                                _this.chuanranbing.labels || [];
                        } else if (key === '预防接种史') {
                            markData[key].forEach((item) => {
                                _this.yufangjiezhong.labels.push({
                                    entity: item.entity,
                                    label: item.label,
                                    start: item.start,
                                    end: item.end,
                                    color:
                                        item.label.search('阴性') !== -1
                                            ? 'success'
                                            : item.label.search('阳性') !== -1
                                            ? 'danger'
                                            : '',
                                });
                            });
                            this.submitFormLabels['预防接种史'] =
                                _this.yufangjiezhong.labels || [];
                        } else if (key === '输血史') {
                            markData[key].forEach((item) => {
                                _this.shuxue.labels.push({
                                    entity: item.entity,
                                    label: item.label,
                                    start: item.start,
                                    end: item.end,
                                    color:
                                        item.label.search('阴性') !== -1
                                            ? 'success'
                                            : item.label.search('阳性') !== -1
                                            ? 'danger'
                                            : '',
                                });
                            });
                            this.submitFormLabels['输血史'] =
                                _this.shuxue.labels || [];
                        } else if (key === '过敏史') {
                            markData[key].forEach((item) => {
                                _this.guomin.labels.push({
                                    entity: item.entity,
                                    label: item.label,
                                    start: item.start,
                                    end: item.end,
                                    color:
                                        item.label.search('阴性') !== -1
                                            ? 'success'
                                            : item.label.search('阳性') !== -1
                                            ? 'danger'
                                            : '',
                                });
                            });
                            this.submitFormLabels['过敏史'] =
                                _this.guomin.labels || [];
                        } else if (key === '初步诊断') {
                            markData[key].forEach((item) => {
                                _this.chubuzhenduan.labels.push({
                                    entity: item.entity,
                                    label: item.label,
                                    start: item.start,
                                    end: item.end,
                                    color:
                                        item.label.search('阴性') !== -1
                                            ? 'success'
                                            : item.label.search('阳性') !== -1
                                            ? 'danger'
                                            : '',
                                });
                            });
                            this.submitFormLabels['初步诊断'] =
                                _this.chubuzhenduan.labels || [];
                        } else if (key === '处理意见') {
                            markData[key].forEach((item) => {
                                _this.chuliyijian.labels.push({
                                    entity: item.entity,
                                    label: item.label,
                                    start: item.start,
                                    end: item.end,
                                    color:
                                        item.label.search('阴性') !== -1
                                            ? 'success'
                                            : item.label.search('阳性') !== -1
                                            ? 'danger'
                                            : '',
                                });
                            });
                            this.submitFormLabels['处理意见'] =
                                _this.chuliyijian.labels || [];
                        } else if (key === '备注') {
                            markData[key].forEach((item) => {
                                _this.beizhu.labels.push({
                                    entity: item.entity,
                                    label: item.label,
                                    start: item.start,
                                    end: item.end,
                                    color:
                                        item.label.search('阴性') !== -1
                                            ? 'success'
                                            : item.label.search('阳性') !== -1
                                            ? 'danger'
                                            : '',
                                });
                            });
                            this.submitFormLabels['初步诊断'] =
                                _this.beizhu.labels || [];
                        } else if (key === '辅助检查') {
                            markData[key].forEach((item) => {
                                _this.fuzhujiancha.labels.push({
                                    entity: item.entity,
                                    label: item.label,
                                    start: item.start,
                                    end: item.end,
                                    color:
                                        item.label.search('阴性') !== -1
                                            ? 'success'
                                            : item.label.search('阳性') !== -1
                                            ? 'danger'
                                            : '',
                                });
                            });
                            this.submitFormLabels['辅助检查'] =
                                _this.fuzhujiancha.labels || [];
                        }
                    });
                    if (!!_this.zhusu.labels && _this.zhusu.labels.length > 1) {
                        _this.zhusu.labels.sort((a, b) => {
                            return a.start - b.start;
                        });
                    }
                    if (
                        !!_this.infoData.personalHistory.labels &&
                        _this.infoData.personalHistory.labels.length > 1
                    ) {
                        _this.infoData.personalHistory.labels.sort((a, b) => {
                            return a.start - b.start;
                        });
                    }
                    if (
                        !!_this.xianbing.labels &&
                        _this.xianbing.labels.length > 1
                    ) {
                        _this.xianbing.labels.sort((a, b) => {
                            return a.start - b.start;
                        });
                    }
                    if (
                        !!_this.infoData.previousHistory.labels &&
                        _this.infoData.previousHistory.labels.length > 1
                    ) {
                        _this.infoData.previousHistory.labels.sort((a, b) => {
                            return a.start - b.start;
                        });
                    }
                    if (
                        !!_this.infoData.operationHistory.labels &&
                        _this.infoData.operationHistory.labels.length > 1
                    ) {
                        _this.infoData.operationHistory.labels.sort((a, b) => {
                            return a.start - b.start;
                        });
                    }
                    if (
                        !!_this.infoData.menstrualHistory.labels &&
                        _this.infoData.menstrualHistory.labels.length > 1
                    ) {
                        _this.infoData.menstrualHistory.labels.sort((a, b) => {
                            return a.start - b.start;
                        });
                    }
                }
            });
        },
        getDiagnosticBasis() {
            this.$axios({
                method: 'GET',
                url: '/PROXY-Remote/dicts/list',
                params: {
                    code: 'diagnosticBasis',
                    page: 0,
                    size: 200,
                },
            }).then(async (res) => {
                if ((await res) && (await res.data.code) === 200) {
                    res.data.data.forEach((item) => {
                        this.diagnosticBasisArray.push({
                            label: item.name,
                            value: item.name,
                            outCode: item.outCode,
                        });
                    });
                    this.diagnosticBasisArray.sort((a, b) => {
                        return parseFloat(a.outCode) - parseFloat(b.outCode);
                    });
                }
            });
        },
    },
};
</script>

<style scoped>
.normal {
    padding: 10px;
    font-size: 14px;
    color: #606266;
}

.btn-item {
    cursor: pointer;
    line-height: 28px;
    padding-left: 10px;
    border-radius: 2px;
}

.is-active {
    color: #ffffff;
    background-color: #10a1df;
}

.btn-item:hover {
    color: #ffffff;
    background-color: #10a1df;
}

.cut-line {
    width: 100%;
    border-bottom: 1px solid #000;
}

.a4 {
    width: 802px;
    height: 100%;
    margin: 0 auto;
    /* background-color: #e6e1e0; */
    background-color: #eeeeee;
    border: 1px solid #000;
    padding: 20px;
}

.a4 .title {
    text-align: center;
    letter-spacing: 2px;
    color: red;
    margin-top: 20px;
    margin-bottom: 20px;
}

.second-title {
    text-align: center;
    font-size: 16px;
}

.heiti {
    font-family: 'SimHei';
    font-size: 16px;
    font-weight: bold;
    line-height: 35px;
}

.limit-height {
    max-height: 600px;
    overflow-y: auto;
}
</style>
